<?php
namespace AdminBundle\Controller;
use BaseBundle\Entity\TestUser;
use BaseBundle\Entity\TestUserAddress;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Serializer\Encoder\JsonEncode;
use Symfony\Component\Serializer\Encoder\JsonEncoder;

/**
 * Created by PhpStorm.
 * User: Alex
 * DateTime: 18-12-29下午2:34
 */
class TestController extends AdminController {

    public function testAction()
    {
        $r = $this->inlet($this->getParameter('return_data'), false);
        if($r !== true){
            return $r;
        }
        set_time_limit(0);
        $data['user_list'] = $this->getData();

        return $this->response('',0,$data);
//        return $this->render('AdminBundle:admin/Test:test.html.twig',$data);
    }


    public function setData()
    {
        $em = $this->getDoctrine()->getEntityManager();

        $user = new TestUser($this->container);
        $address = new TestUserAddress($this->container);

        $user->setName('孬子');

        $address->setName('孬子的地址');
        $address->setTestUser($user);
        $user->addTestUserAddress($address);

        $em->persist($user);
        $em->persist($address);

        $em->flush();
    }

    public function getData($page = 1,$limit = 15)
    {
        $repository = $this->getDoctrine()->getRepository('BaseBundle:TestUser');
        return $repository->getListByPage($page,$limit);
    }

}